<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>人员资质-资质管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<table class="layui-hide" id="dataList" lay-filter="dataList"></table>
<script type="text/html" id="toolbarOrg">
    <div class="layui-btn-container">
    </div>
</script>

<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    layui.use(['jquery', 'configureCom', 'configure', 'table', 'sessionFun'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var matchDict = layui.matchDict;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var configureCom = layui.configureCom;

        var cols = [[
            {
                field: 'registerType', title: '证书类别', templet: function (d) {
                    return '<p>' + matchDict.name(d.registerType, configure.CERT_TYPE_CODE) + '</p>'
                }
            },
            {field: 'aptitudeNumber', title: '证书编号'},
            {field: 'grantTime', title: '发证日期'},
            {field: 'aptitudeOrg', title: '发证机关'},
            {
                field: 'aptitudeStatus', title: '状态', templet: function (d) {
                    return '<p>' + matchDict.name(d.aptitudeStatus, configure.USER_APTITUDE_STATUS) + '</p>';
                }
            }
        ]];
        configureCom.tableRender(configure.ZIZHI_CERT_ALL_LIST_HTTP, {aptitudeStatus: 2}, cols, 'dataList', 10, '', 'toolbarOrg');

        //头工具栏事件
        table.on('toolbar(dataList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            sessionFun.remove(configure.SESSION_LIST_DATA);
            switch (obj.event) {
                case 'add':
                    editItem('添加', configure.ZIZHI_CERT_SAVE_HTTP);
                    break;
                case 'del':
                    var data = checkStatus.data;
                    if (!data.length) {
                        top.layer.alert('请您至少选择一条数据后再提交！');
                        return false;
                    }
                    top.layer.confirm('您真的要删除选中的数据吗？', function (index, layero) {
                        top.layer.close(index);
                        var ids = '';
                        $(data).each(function (index, item) {
                            if (!index) {
                                ids = item.id;
                            } else {
                                ids += ',' + item.id;
                            }
                        });
                        deleteFun(ids);
                    });
                    break;
            }
        });
        //每行操作
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.SESSION_LIST_DATA, data);
            if (obj.event === 'del') {//查看详情
                deleteFun(data.id);
            } else if (obj.event === 'edit') {
                editItem('修改', configure.ZIZHI_CERT_UPDATE_HTTP)
            } else if (obj.event === 'submit') {
                top.layer.confirm('确定要提交吗？提交后不可删除。', function (index, layero) {
                    configureCom.postDataAjax(configure.ZIZHI_CERT_SUBMIT_HTTP, {userAptitudeId: data.id}).then(function (res) {
                        if (res.code == 0) {
                            top.layer.msg('设置成功！');
                            top.layer.close('设置成功！');
                            configureCom.tableReload(true);
                        }
                    });
                });
            }
        });

        function deleteFun(ids) {
            configureCom.postDataAjax(configure.ZIZHI_CERT_DELETE_HTTP, {userAptitudeIds: ids}).then(function (res) {
                if (res.code == 0) {
                    top.layer.msg('删除成功！');
                    configureCom.tableReload(true);
                } else {
                    top.layer.alert('删除失败！');
                }
            });
        }

        //新增或修改字典详情
        function editItem(title, url) {
            top.layer.open({
                type: 2,
                title: title,
                area: configureCom.Psize1,
                content: configureCom.nocache(configure.ZIZHI_CERT_DETAIL_HTML),
                btn: ['保存', '关闭'],
                btnAlign: 'c',
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    var data = iframeWin.getData();
                    configureCom.postDataAjax(url, data).then(function (res) {
                        if (res.code == 0) {
                            top.layer.close(index);
                            top.layer.msg('保存成功！');
                            configureCom.tableReload(true);
                        } else {
                            top.layer.alert('保存失败！');
                        }
                    });
                }
            });
        }
    });

</script>
</body>
</html>